package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbGoodsProtection;
import com.ruoyi.system.service.ITbGoodsProtectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品保障Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/protection")
public class TbGoodsProtectionController extends BaseController
{
    @Autowired
    private ITbGoodsProtectionService tbGoodsProtectionService;

    /**
     * 查询商品保障列表
     */
    @PreAuthorize("@ss.hasPermi('system:protection:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbGoodsProtection tbGoodsProtection)
    {
        startPage();
        List<TbGoodsProtection> list = tbGoodsProtectionService.selectTbGoodsProtectionList(tbGoodsProtection);
        return getDataTable(list);
    }

    /**
     * 导出商品保障列表
     */
    @PreAuthorize("@ss.hasPermi('system:protection:export')")
    @Log(title = "商品保障", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbGoodsProtection tbGoodsProtection)
    {
        List<TbGoodsProtection> list = tbGoodsProtectionService.selectTbGoodsProtectionList(tbGoodsProtection);
        ExcelUtil<TbGoodsProtection> util = new ExcelUtil<TbGoodsProtection>(TbGoodsProtection.class);
        util.exportExcel(response, list, "商品保障数据");
    }

    /**
     * 获取商品保障详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:protection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbGoodsProtectionService.selectTbGoodsProtectionById(id));
    }

    /**
     * 新增商品保障
     */
    @PreAuthorize("@ss.hasPermi('system:protection:add')")
    @Log(title = "商品保障", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbGoodsProtection tbGoodsProtection)
    {
        return toAjax(tbGoodsProtectionService.insertTbGoodsProtection(tbGoodsProtection));
    }

    /**
     * 修改商品保障
     */
    @PreAuthorize("@ss.hasPermi('system:protection:edit')")
    @Log(title = "商品保障", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbGoodsProtection tbGoodsProtection)
    {
        return toAjax(tbGoodsProtectionService.updateTbGoodsProtection(tbGoodsProtection));
    }

    /**
     * 删除商品保障
     */
    @PreAuthorize("@ss.hasPermi('system:protection:remove')")
    @Log(title = "商品保障", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbGoodsProtectionService.deleteTbGoodsProtectionByIds(ids));
    }
}
